import axios from "axios";
// import Cookies from "js-cookie";
axios.defaults.withCredentials = true;
const service = axios.create({
  // baseURL: process.env.BASE_API, // api的base_url
  baseURL: "http://172.25.253.114:28080/km-gradms-core-server/", // api的base_url
  timeout: 5000, // request timeout
  headers: {
    "X-Requested-With": "XMLHttpRequest"
  },
  withCredentials: true
});
// request interceptor
service.interceptors.request.use(
  config => {
    const { _setMock } = config.params || "";
    if (_setMock != undefined) {
      config.baseURL = "";
    }
    config.headers["Accept"] =
      "application/json, text/javascript, */*; q=0.01";
    config.headers["Content-Type"] =
      "application/x-www-form-urlencoded; charset=UTF-8";
    return config;
  },
  error => {
    // Do something with request error
    Promise.reject(error);
  }
);
service.credentials = true;
service.defaults.withCredentials = true;

// respone interceptor
service.interceptors.response.use(
  // response => response,
  /**
   * 下面的注释为通过在response里，自定义code来标示请求状态
   * 当code返回如下情况则说明权限有问题，登出并返回到登录页
   * 如想通过xmlhttprequest来状态码标识 逻辑可写在下面error中
   * 以下代码均为样例，请结合自生需求加以修改，若不需要，则可删除
   */
  response => {

    return response.data;
  },
  error => {
    return Promise.reject(error);
  }
);
service.defaults.withCredentials = true;
export default service;
